//
//  MFWStringUtils.m
//  MFWSdk
//
//  Created by Song Xiaofeng on 13-7-26.
//  Copyright (c) 2013年 Mafengwo Inc. All rights reserved.
//

#import "MFWStringUtils.h"
#import "Base64.h"
#import <CommonCrypto/CommonHMAC.h>
@implementation MFWStringUtils

+ (BOOL)isEmptyString:(NSString*)string;
{
    if (string && [string isKindOfClass:[NSString class] ] && [string length] > 0)
    {
        return NO;
    }
    return YES;
}

+ (NSString*)hmac_sha1:(NSString*)key text:(NSString*)text
{
    const char *cKey  = [key cStringUsingEncoding:NSUTF8StringEncoding];
    const char *cData = [text cStringUsingEncoding:NSUTF8StringEncoding];
    
    char cHMAC[CC_SHA1_DIGEST_LENGTH];
    
    CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
    
    NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:CC_SHA1_DIGEST_LENGTH];
    NSString *hash = [Base64 stringByEncodingData:HMAC];//base64 编码。

    return hash;
}
@end
